﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VRacer.Packets
{
    public class WelcomePacket : PacketBase
    {
        private int _version = 1;
        private int _id;
        private string _trackID;

        public WelcomePacket()
            : base(PacketType.Welcome)
        {
            base.Length += 4;
            this.ID = this.GetHashCode();
        }

        public int ID
        {
            get { return _id; }
            set { _id = value; }
        }

        public override int Length
        {
            get
            {
                return base.Length + UTF8Encoding.UTF8.GetByteCount(_trackID);
            }
        }

        public string TrackID
        {
            get { return _trackID; }
            set { _trackID = value; }
        }


        public int Version
        {
            get { return _version; }
            set { _version = value; }
        }

        public override void Read(System.IO.BinaryReader reader)
        {
            base.Read(reader);

            _version = reader.ReadInt32();
            _id = reader.ReadInt32();
            _trackID = reader.ReadString();
        }

        public override void Write(System.IO.BinaryWriter writer)
        {
            base.Write(writer);

            writer.Write(_version);
            writer.Write(_id);
            writer.Write(_trackID);
        }
    }
}
